/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ivanbiz.quiz;

import com.ivanbiz.generic.GenericDAOImpl;
import java.util.List;
import org.hibernate.Query;

/**
 *
 * @author User
 */
public class AnswerDAOImpl extends GenericDAOImpl implements AnswerDAO{

    public List getAnswerByTitle(String idTitle) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Answer a where a.titleId=:id order by a.question.id");
        query.setParameter("id", idTitle);
        return query.list();
    }

    public List getAnswerByQuestion(long idQuestion) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Answer a where a.question.id=:id order by a.question.id");
        query.setParameter("id", idQuestion);
        return query.list();
    }

    public void deleteByQuestion(long idQuestion) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("delete from Answer a where a.question.id=:id");
        query.setParameter("id", idQuestion);
    }

    public void deleteByTitle(String idTitle) throws Exception {
         Query query = getSessionFactory().getCurrentSession().createQuery("delete from Answer a where a.titleId=:id");
        query.setParameter("id", idTitle);
    }

}
